<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>CSS 学习笔记-继承性与层叠性 | KnightSama‘s Blog</title>
    <meta name="description" content="Hello, my friend!">
    <link rel="icon" href="/favicon.ico">
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
  <script src="https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/@babel/standalone/babel.min.js"></script>
    
    <link rel="preload" href="/assets/css/0.styles.c4ea52a5.css" as="style"><link rel="preload" href="/assets/js/app.a2483de7.js" as="script"><link rel="preload" href="/assets/js/4.0078dadf.js" as="script"><link rel="preload" href="/assets/js/1.c3e7d2b0.js" as="script"><link rel="preload" href="/assets/js/29.90552487.js" as="script"><link rel="prefetch" href="/assets/js/10.265e4f40.js"><link rel="prefetch" href="/assets/js/11.a3a2f8c1.js"><link rel="prefetch" href="/assets/js/12.1910f8cc.js"><link rel="prefetch" href="/assets/js/13.229fa478.js"><link rel="prefetch" href="/assets/js/14.c27d4a17.js"><link rel="prefetch" href="/assets/js/15.92adafd4.js"><link rel="prefetch" href="/assets/js/16.bcee7c14.js"><link rel="prefetch" href="/assets/js/17.ee1bcf41.js"><link rel="prefetch" href="/assets/js/18.fa3c3a4e.js"><link rel="prefetch" href="/assets/js/19.1a943c57.js"><link rel="prefetch" href="/assets/js/20.44781dae.js"><link rel="prefetch" href="/assets/js/21.1fe46223.js"><link rel="prefetch" href="/assets/js/22.6f7d46c2.js"><link rel="prefetch" href="/assets/js/23.56223d02.js"><link rel="prefetch" href="/assets/js/24.e7cad43b.js"><link rel="prefetch" href="/assets/js/25.b2902552.js"><link rel="prefetch" href="/assets/js/26.70698c07.js"><link rel="prefetch" href="/assets/js/27.6ee3d263.js"><link rel="prefetch" href="/assets/js/28.ce131de6.js"><link rel="prefetch" href="/assets/js/30.b3291ccc.js"><link rel="prefetch" href="/assets/js/31.ea8c441e.js"><link rel="prefetch" href="/assets/js/32.3e29bbeb.js"><link rel="prefetch" href="/assets/js/33.65e78c5e.js"><link rel="prefetch" href="/assets/js/34.3ba19d7c.js"><link rel="prefetch" href="/assets/js/35.66d3fc4a.js"><link rel="prefetch" href="/assets/js/36.f5725281.js"><link rel="prefetch" href="/assets/js/37.f5b0b5ff.js"><link rel="prefetch" href="/assets/js/38.3cae3054.js"><link rel="prefetch" href="/assets/js/39.47dc1ffe.js"><link rel="prefetch" href="/assets/js/5.f0714e2e.js"><link rel="prefetch" href="/assets/js/6.53240a5f.js"><link rel="prefetch" href="/assets/js/7.dc126a6b.js"><link rel="prefetch" href="/assets/js/8.86452400.js"><link rel="prefetch" href="/assets/js/9.16ef06de.js"><link rel="prefetch" href="/assets/js/vendors~flowchart.734d5d92.js">
    <link rel="stylesheet" href="/assets/css/0.styles.c4ea52a5.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div><div class="theme-container" data-v-0cb1c278><div data-v-0cb1c278><div id="loader-wrapper" class="loading-wrapper" data-v-4b73742e data-v-0cb1c278 data-v-0cb1c278><div class="loader-main" data-v-4b73742e><div data-v-4b73742e></div><div data-v-4b73742e></div><div data-v-4b73742e></div><div data-v-4b73742e></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-da0660ba data-v-0cb1c278 data-v-0cb1c278><h3 class="title" style="display:none;" data-v-da0660ba data-v-da0660ba>KnightSama‘s Blog</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-da0660ba data-v-da0660ba><input type="password" value="" data-v-da0660ba> <span data-v-da0660ba>Konck! Knock!</span> <button data-v-da0660ba>OK</button></label> <div class="footer" style="display:none;" data-v-da0660ba data-v-da0660ba><span data-v-da0660ba><i class="iconfont reco-theme" data-v-da0660ba></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-da0660ba>vuePress-theme-reco</a></span> <span data-v-da0660ba><i class="iconfont reco-copyright" data-v-da0660ba></i> <a data-v-da0660ba><span data-v-da0660ba>KnightSama</span>
            
          <!---->
          2021
        </a></span></div></div> <div class="hide" data-v-0cb1c278><header class="navbar" data-v-0cb1c278><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/Misaka.jpg" alt="KnightSama‘s Blog" class="logo"> <span class="site-name">KnightSama‘s Blog</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/iOS/" class="nav-link"><i class="iconfont undefined"></i>
  iOS
</a></li><li class="dropdown-item"><!----> <a href="/categories/集锦/" class="nav-link"><i class="iconfont undefined"></i>
  集锦
</a></li><li class="dropdown-item"><!----> <a href="/categories/JavaScript/" class="nav-link"><i class="iconfont undefined"></i>
  JavaScript
</a></li><li class="dropdown-item"><!----> <a href="/categories/Github/" class="nav-link"><i class="iconfont undefined"></i>
  Github
</a></li><li class="dropdown-item"><!----> <a href="/categories/Python/" class="nav-link"><i class="iconfont undefined"></i>
  Python
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><a href="https://github.com/KnightSama" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-0cb1c278></div> <aside class="sidebar" data-v-0cb1c278><div class="personal-info-wrapper" data-v-4a3def3c><img src="/Misaka.jpg" alt="author-avatar" class="personal-img" data-v-4a3def3c> <h3 class="name" data-v-4a3def3c>
    KnightSama
  </h3> <div class="num" data-v-4a3def3c><div data-v-4a3def3c><h3 data-v-4a3def3c>27</h3> <h6 data-v-4a3def3c>文章</h6></div> <div data-v-4a3def3c><h3 data-v-4a3def3c>14</h3> <h6 data-v-4a3def3c>标签</h6></div></div> <hr data-v-4a3def3c></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/iOS/" class="nav-link"><i class="iconfont undefined"></i>
  iOS
</a></li><li class="dropdown-item"><!----> <a href="/categories/集锦/" class="nav-link"><i class="iconfont undefined"></i>
  集锦
</a></li><li class="dropdown-item"><!----> <a href="/categories/JavaScript/" class="nav-link"><i class="iconfont undefined"></i>
  JavaScript
</a></li><li class="dropdown-item"><!----> <a href="/categories/Github/" class="nav-link"><i class="iconfont undefined"></i>
  Github
</a></li><li class="dropdown-item"><!----> <a href="/categories/Python/" class="nav-link"><i class="iconfont undefined"></i>
  Python
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><a href="https://github.com/KnightSama" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>CSS 学习笔记-继承性与层叠性</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/Views/20200324.html#继承性" class="sidebar-link">继承性</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/Views/20200324.html#层叠性" class="sidebar-link">层叠性</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/Views/20200324.html#选择器权重" class="sidebar-link">选择器权重</a></li><li class="sidebar-sub-header"><a href="/Views/20200324.html#根据选择器数量计算权重" class="sidebar-link">根据选择器数量计算权重</a></li><li class="sidebar-sub-header"><a href="/Views/20200324.html#未直接选中元素时的权重计算" class="sidebar-link">未直接选中元素时的权重计算</a></li><li class="sidebar-sub-header"><a href="/Views/20200324.html#样式表权重" class="sidebar-link">样式表权重</a></li><li class="sidebar-sub-header"><a href="/Views/20200324.html#使用-important-提高权重" class="sidebar-link">使用 !important 提高权重</a></li><li class="sidebar-sub-header"><a href="/Views/20200324.html#权重总结" class="sidebar-link">权重总结</a></li></ul></li></ul></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-da0660ba data-v-0cb1c278><h3 class="title" style="display:none;" data-v-da0660ba data-v-da0660ba>CSS 学习笔记-继承性与层叠性</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-da0660ba data-v-da0660ba><input type="password" value="" data-v-da0660ba> <span data-v-da0660ba>Konck! Knock!</span> <button data-v-da0660ba>OK</button></label> <div class="footer" style="display:none;" data-v-da0660ba data-v-da0660ba><span data-v-da0660ba><i class="iconfont reco-theme" data-v-da0660ba></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-da0660ba>vuePress-theme-reco</a></span> <span data-v-da0660ba><i class="iconfont reco-copyright" data-v-da0660ba></i> <a data-v-da0660ba><span data-v-da0660ba>KnightSama</span>
            
          <!---->
          2021
        </a></span></div></div> <div data-v-0cb1c278><main class="page"><div class="sidebar-open-close"><svg xmlns="http://www.w3.org/2000/svg" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <!----> <div class="page-title" style="display:none;"><h1>CSS 学习笔记-继承性与层叠性</h1> <hr> <div data-v-73367bb4><i class="iconfont reco-account" data-v-73367bb4><span data-v-73367bb4>KnightSama</span></i> <i class="iconfont reco-date" data-v-73367bb4><span data-v-73367bb4>2020-03-24</span></i> <i class="iconfont reco-eye" data-v-73367bb4><span id="/Views/20200324.html" data-flag-title="Your Article Title" class="leancloud-visitors" data-v-73367bb4><a class="leancloud-visitors-count" style="font-size:.9rem;font-weight:normal;color:#999;"></a></span></i> <i class="iconfont reco-tag tags" data-v-73367bb4><span class="tag-item" data-v-73367bb4>
      CSS
    </span></i></div></div> <div class="theme-reco-content content__default" style="display:none;"><p>继承性与层叠性是 CSS 的重要特性，继承性就是子组件会继承父组件的某些样式，这样我们就不需要给每个子组件都去设置样式。层叠性是对设置样式过程中可能导致的冲突问题进行处理。
</p> <h2 id="继承性"><a href="#继承性" class="header-anchor">#</a> 继承性</h2> <p>继承性是子标签会使用父标签的某些样式，如果我们需要对某个标签下的所有后代标签都需要设置相同的样式，此时我们可以通过继承性将样式设置在父标签上，而不需要对每个子标签进行设置</p> <div data-config="" data-type="vanilla" data-code="%3Chtml%3E%0A%0A%3Cstyle%3E%0A%20%20%20%20.test1%20%7B%0A%20%20%20%20%20%20%20%20color%3A%20red%3B%0A%20%20%20%20%20%20%20%20border%3A%201px%20green%20solid%3B%0A%20%20%20%20%7D%0A%3C%2Fstyle%3E%0A%0A%3Cdiv%20class%3D%22test1%22%3E%0A%20%20%20%20%3Cp%3E%E6%AD%A4%E6%A0%87%E7%AD%BE%E7%9A%84%E5%AD%97%E4%BD%93%E9%A2%9C%E8%89%B2%E7%BB%A7%E6%89%BF%E8%87%AA%20div%20%E6%A0%87%E7%AD%BE%3C%2Fp%3E%0A%20%20%20%20%3Cp%3E%E6%89%80%E6%9C%89%E5%90%8E%E4%BB%A3%E6%A0%87%E7%AD%BE%E9%83%BD%E4%BC%9A%E7%BB%A7%E6%89%BF%3C%2Fp%3E%0A%3C%2Fdiv%3E%0A%0A%3C%2Fhtml%3E%0A" class="vuepress-plugin-demo-block__wrapper" style="display:none;"><div class="vuepress-plugin-demo-block__display"><div class="vuepress-plugin-demo-block__app"></div></div> <div class="vuepress-plugin-demo-block__code"><div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
    <span class="token selector">.test1</span> <span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
        <span class="token property">border</span><span class="token punctuation">:</span> 1px green solid<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>test1<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>此标签的字体颜色继承自 div 标签<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>所有后代标签都会继承<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div></div> <div class="vuepress-plugin-demo-block__footer"></div></div> <p>通过上面的例子我们看到设置到  <code>&lt;div&gt;</code>  上的字体样式被两个后代  <code>&lt;p&gt;</code>  标签所继承，但是设置的边框样式只有  <code>&lt;div&gt;</code>  生效，两个后代标签没有继承。因此并不是所有的样式都会被继承，关于字体样式的属性如  <code>color</code>  和以  <code>font-</code>  、 <code>text-</code>  、 <code>line-</code>  开头的属性大多都能继承，但有关定位、布局的属性不能被继承。在使用继承性的时候一定要注意哪些属性会被继承，哪些不会继承。</p> <h2 id="层叠性"><a href="#层叠性" class="header-anchor">#</a> 层叠性</h2> <p>我们知道 CSS 有多种选择器，不同的选择器可以选中相同的标签，此时如果定义了冲突的样式就需要通过优先级来确定最终应用哪种样式。</p> <div data-config="" data-type="vanilla" data-code="%3Chtml%3E%0A%0A%3Cstyle%3E%0A%20%20%20%20.test2%20p%20%7B%0A%20%20%20%20%20%20%20%20color%3A%20green%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20.test2%20.red-color%20%7B%0A%20%20%20%20%20%20%20%20color%3A%20red%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20.test2%20%23blue-color%20%7B%0A%20%20%20%20%20%20%20%20color%3A%20blue%3B%0A%20%20%20%20%7D%0A%3C%2Fstyle%3E%0A%0A%3Cdiv%20class%3D%22test2%22%3E%0A%20%20%20%20%3Cp%20class%3D%22red-color%22%20id%3D%22blue-color%22%3E%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E9%A2%9C%E8%89%B2%3C%2Fp%3E%0A%3C%2Fdiv%3E%0A%0A%3C%2Fhtml%3E%0A" class="vuepress-plugin-demo-block__wrapper" style="display:none;"><div class="vuepress-plugin-demo-block__display"><div class="vuepress-plugin-demo-block__app"></div></div> <div class="vuepress-plugin-demo-block__code"><div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
    <span class="token selector">.test2 p</span> <span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> green<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token selector">.test2 .red-color</span> <span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    <span class="token selector">.test2 #blue-color</span> <span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> blue<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>test2<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>red-color<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>blue-color<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>设置文本颜色<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div></div> <div class="vuepress-plugin-demo-block__footer"></div></div> <p>上面的例子中我们通过三种不同的方式设置了  <code>&lt;p&gt;</code>  标签的文本颜色，最终文本显示为蓝色。这里就用到了层叠性，说明将文本设置为蓝色的选择器具有最高的优先级。</p> <h3 id="选择器权重"><a href="#选择器权重" class="header-anchor">#</a> 选择器权重</h3> <p>在计算权重时，不同的选择器具有不同的权重。当多个选择器选中某个元素时，按照如下顺序统计权重</p> <ul><li>id 选择器</li> <li>类选择器、属性选择器、伪类选择器</li> <li>标签选择器、伪元素选择器</li></ul> <p>对于相同方式的样式表，选择器的优先级为: id 选择器 &gt; 类选择器 &gt; 标签选择器</p> <h3 id="根据选择器数量计算权重"><a href="#根据选择器数量计算权重" class="header-anchor">#</a> 根据选择器数量计算权重</h3> <p>当多个选择器选中相同元素时，我们可以分别统计这些选中目标元素的选择器中各种选择器的数量，然后按照选择器的权重由高到低依次比较，带有高权重选择器数量多的胜出。</p> <div data-config="" data-type="vanilla" data-code="%3Chtml%3E%0A%0A%3Cstyle%3E%0A%20%20%20%20.test3%20%23div1%20.class2%20p%20%7B%0A%20%20%20%20%20%20%20%20%2F*%201%20%E4%B8%AA%20id%20%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%8C2%20%E4%B8%AA%E7%B1%BB%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%8C1%20%E4%B8%AA%E6%A0%87%E7%AD%BE%E9%80%89%E6%8B%A9%E5%99%A8%20*%2F%0A%20%20%20%20%20%20%20%20color%3A%20green%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20.test3%20div%20div%20%23div3%20p%20%7B%0A%20%20%20%20%20%20%20%20%2F*%201%20%E4%B8%AA%20id%20%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%8C1%20%E4%B8%AA%E7%B1%BB%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%8C3%20%E4%B8%AA%E6%A0%87%E7%AD%BE%E9%80%89%E6%8B%A9%E5%99%A8%20*%2F%0A%20%20%20%20%20%20%20%20color%3A%20red%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20.test3%20div.class1%20div.class2%20div.class3%20p%20%7B%0A%20%20%20%20%20%20%20%20%2F*%200%20%E4%B8%AA%20id%20%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%8C4%20%E4%B8%AA%E7%B1%BB%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%8C4%20%E4%B8%AA%E6%A0%87%E7%AD%BE%E9%80%89%E6%8B%A9%E5%99%A8%20*%2F%0A%20%20%20%20%20%20%20%20color%3A%20blue%3B%0A%20%20%20%20%7D%0A%3C%2Fstyle%3E%0A%0A%3Cdiv%20class%3D%22test3%22%3E%0A%20%20%20%20%3Cdiv%20class%3D%22class1%22%20id%3D%22div1%22%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22class2%22%20id%3D%22div2%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22class3%22%20id%3D%22div3%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cp%3E%E6%88%91%E7%9A%84%E9%A2%9C%E8%89%B2%E6%98%AF%E4%BB%80%E4%B9%88%3C%2Fp%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%0A%3C%2Fhtml%3E%0A" class="vuepress-plugin-demo-block__wrapper" style="display:none;"><div class="vuepress-plugin-demo-block__display"><div class="vuepress-plugin-demo-block__app"></div></div> <div class="vuepress-plugin-demo-block__code"><div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
    <span class="token selector">.test3 #div1 .class2 p</span> <span class="token punctuation">{</span>
        <span class="token comment">/* 1 个 id 选择器，2 个类选择器，1 个标签选择器 */</span>
        <span class="token property">color</span><span class="token punctuation">:</span> green<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token selector">.test3 div div #div3 p</span> <span class="token punctuation">{</span>
        <span class="token comment">/* 1 个 id 选择器，1 个类选择器，3 个标签选择器 */</span>
        <span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    <span class="token selector">.test3 div.class1 div.class2 div.class3 p</span> <span class="token punctuation">{</span>
        <span class="token comment">/* 0 个 id 选择器，4 个类选择器，4 个标签选择器 */</span>
        <span class="token property">color</span><span class="token punctuation">:</span> blue<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>test3<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class1<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div1<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class2<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div2<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class3<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div3<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>我的颜色是什么<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br></div></div></div> <div class="vuepress-plugin-demo-block__footer"></div></div> <p>上面的例子中通过三种选择器选中了  <code>&lt;p&gt;</code>  标签并同时设置了文本颜色，此时各样式的权重计算如下:</p> <p>首先统计各选择器中 id 选择器、类选择器、标签选择器的数量，这里以颜色区分</p> <ul><li>设置绿色字体样式的选择器有 1 个 id 选择器，2 个类选择器，1 个标签选择器</li> <li>设置红色字体样式的选择器有 1 个 id 选择器，1 个类选择器，3 个标签选择器</li> <li>设置蓝色字体样式的选择器有 0 个 id 选择器，4 个类选择器，4 个标签选择器</li></ul> <p>根据选择器优先级依次比较数量确定整体优先级</p> <ul><li>绿色样式与红色样式都有 1 个 id 选择器，蓝色字体样式没有 id 选择器，因此蓝色字体样式优先级最低淘汰</li> <li>绿色样式与红色样式 id 选择器数量相同看下一级选择器，绿色样式有 2 个类选择器，红色样式有 1 个类选择器，绿色样式的类选择器更多故绿色样式优先级最高，最终字体颜色为绿色</li></ul> <div class="custom-block tip"><p class="custom-block-title">交并集选择器计算</p> <p>交集选择器要拆开后共同计算，如  <code>div.class1</code>  是一个类选择器加一个标签选择器</p> <p>并集选择器要按  <code>,</code>  隔开后分别计算每一部分的权重，看做多个选择器来计算</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">div #test , .class1 div</span> <span class="token punctuation">{</span>
    <span class="token comment">/* 这里要拆成 div #test 与 .class1 div 两部分当做两个选择器分别计算权重 */</span>
    <span class="token property">color</span> <span class="token punctuation">:</span> red<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></div> <h4 id="选择器权重相同时的就近原则"><a href="#选择器权重相同时的就近原则" class="header-anchor">#</a> 选择器权重相同时的就近原则</h4> <p>如果选中标签的选择器权重相同时，则写在后面的样式生效，这就是就近原则。</p> <div data-config="" data-type="vanilla" data-code="%3Chtml%3E%0A%0A%3Cstyle%3E%0A%20%20%20%20.test4%20%23div1%20.class2%20p%20%7B%0A%20%20%20%20%20%20%20%20%2F*%201%20%E4%B8%AA%20id%20%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%8C2%20%E4%B8%AA%E7%B1%BB%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%8C1%20%E4%B8%AA%E6%A0%87%E7%AD%BE%E9%80%89%E6%8B%A9%E5%99%A8%20*%2F%0A%20%20%20%20%20%20%20%20color%3A%20green%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20.test4%20.class2%20%23div3%20p%20%7B%0A%20%20%20%20%20%20%20%20%2F*%201%20%E4%B8%AA%20id%20%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%8C2%20%E4%B8%AA%E7%B1%BB%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%8C1%20%E4%B8%AA%E6%A0%87%E7%AD%BE%E9%80%89%E6%8B%A9%E5%99%A8%20*%2F%0A%20%20%20%20%20%20%20%20color%3A%20red%3B%0A%20%20%20%20%7D%0A%3C%2Fstyle%3E%0A%0A%3Cdiv%20class%3D%22test4%22%3E%0A%20%20%20%20%3Cdiv%20class%3D%22class1%22%20id%3D%22div1%22%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22class2%22%20id%3D%22div2%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22class3%22%20id%3D%22div3%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cp%3E%E6%88%91%E7%9A%84%E9%A2%9C%E8%89%B2%E6%98%AF%E4%BB%80%E4%B9%88%3C%2Fp%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%0A%3C%2Fhtml%3E%0A" class="vuepress-plugin-demo-block__wrapper" style="display:none;"><div class="vuepress-plugin-demo-block__display"><div class="vuepress-plugin-demo-block__app"></div></div> <div class="vuepress-plugin-demo-block__code"><div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
    <span class="token selector">.test4 #div1 .class2 p</span> <span class="token punctuation">{</span>
        <span class="token comment">/* 1 个 id 选择器，2 个类选择器，1 个标签选择器 */</span>
        <span class="token property">color</span><span class="token punctuation">:</span> green<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token selector">.test4 .class2 #div3 p</span> <span class="token punctuation">{</span>
        <span class="token comment">/* 1 个 id 选择器，2 个类选择器，1 个标签选择器 */</span>
        <span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>test4<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class1<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div1<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class2<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div2<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class3<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div3<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>我的颜色是什么<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div></div> <div class="vuepress-plugin-demo-block__footer"></div></div> <p>上面的例子中绿色样式与红色样式的各类选择器数量相同因此权重相同，因为红色样式写在后面所以红色样式生效</p> <h3 id="未直接选中元素时的权重计算"><a href="#未直接选中元素时的权重计算" class="header-anchor">#</a> 未直接选中元素时的权重计算</h3> <p>如果样式选择器最终没有直接选中目标元素而是通过继承的方式影响的元素样式也就是选中了目标元素的父元素，此时这个选择器对于该元素权重为 0。</p> <div data-config="" data-type="vanilla" data-code="%3Chtml%3E%0A%0A%3Cstyle%3E%0A%20%20%20%20.test5%20%23div1%20%23div2%20%23div3%20%7B%0A%20%20%20%20%20%20%20%20%2F*%20%E6%B2%A1%E6%9C%89%E7%9B%B4%E6%8E%A5%E9%80%89%E4%B8%AD%20p%20%E5%9B%A0%E6%AD%A4%E6%9D%83%E9%87%8D%E4%B8%BA%200%20*%2F%0A%20%20%20%20%20%20%20%20color%3A%20green%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20.test5%20p%20%7B%0A%20%20%20%20%20%20%20%20color%3A%20red%3B%0A%20%20%20%20%7D%0A%3C%2Fstyle%3E%0A%0A%3Cdiv%20class%3D%22test5%22%3E%0A%20%20%20%20%3Cdiv%20class%3D%22class1%22%20id%3D%22div1%22%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22class2%22%20id%3D%22div2%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22class3%22%20id%3D%22div3%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cp%3E%E6%88%91%E7%9A%84%E9%A2%9C%E8%89%B2%E6%98%AF%E4%BB%80%E4%B9%88%3C%2Fp%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%0A%3C%2Fhtml%3E%0A" class="vuepress-plugin-demo-block__wrapper" style="display:none;"><div class="vuepress-plugin-demo-block__display"><div class="vuepress-plugin-demo-block__app"></div></div> <div class="vuepress-plugin-demo-block__code"><div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
    <span class="token selector">.test5 #div1 #div2 #div3</span> <span class="token punctuation">{</span>
        <span class="token comment">/* 没有直接选中 p 因此权重为 0 */</span>
        <span class="token property">color</span><span class="token punctuation">:</span> green<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token selector">.test5 p</span> <span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>test5<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class1<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div1<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class2<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div2<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class3<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div3<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>我的颜色是什么<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div></div> <div class="vuepress-plugin-demo-block__footer"></div></div> <p>上面的例子中虽然绿色样式带有 3 个 id 选择器，但由于其并没有直接选中  <code>&lt;p&gt;</code>  标签，因此其权重为 0，因此最终文本颜色为红色。</p> <div class="custom-block tip"><p>在计算权重的过程中要首先看是否直接选中了目标元素。</p></div> <h4 id="继承时权重相同的就近原则"><a href="#继承时权重相同的就近原则" class="header-anchor">#</a> 继承时权重相同的就近原则</h4> <p>如果目标选择器权重都为 0，说明其样式完全来自继承的父元素样式，此时只需去计算其父元素样式权重即可</p> <div data-config="" data-type="vanilla" data-code="%3Chtml%3E%0A%0A%3Cstyle%3E%0A%20%20%20%20.test6%20.class3%20%7B%0A%20%20%20%20%20%20%20%20color%3A%20green%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20.test6%20%23div2%20%7B%0A%20%20%20%20%20%20%20%20color%3A%20red%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20.test6%20%23div3%20%7B%0A%20%20%20%20%20%20%20%20color%3A%20blue%3B%0A%20%20%20%20%7D%0A%0A%3C%2Fstyle%3E%0A%0A%3Cdiv%20class%3D%22test6%22%3E%0A%20%20%20%20%3Cdiv%20class%3D%22class1%22%20id%3D%22div1%22%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22class2%22%20id%3D%22div2%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22class3%22%20id%3D%22div3%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cp%3E%E6%88%91%E7%9A%84%E9%A2%9C%E8%89%B2%E6%98%AF%E4%BB%80%E4%B9%88%3C%2Fp%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%0A%3C%2Fhtml%3E%0A" class="vuepress-plugin-demo-block__wrapper" style="display:none;"><div class="vuepress-plugin-demo-block__display"><div class="vuepress-plugin-demo-block__app"></div></div> <div class="vuepress-plugin-demo-block__code"><div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
    <span class="token selector">.test6 .class3</span> <span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> green<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token selector">.test6 #div2</span> <span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    <span class="token selector">.test6 #div3</span> <span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> blue<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>test6<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class1<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div1<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class2<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div2<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class3<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div3<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>我的颜色是什么<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br></div></div></div> <div class="vuepress-plugin-demo-block__footer"></div></div> <p>上面的例子中没有选择器直接选中  <code>&lt;p&gt;</code>  标签，因此权重均为 0，此时  <code>&lt;p&gt;</code>  标签的样式继承自父标签，因此计算父标签的样式。绿色样式选中了  <code>&lt;p&gt;</code>  标签的父标签  <code>&lt;div&gt;</code>  并有 2 个类选择器，红色样式选中了  <code>&lt;p&gt;</code>  标签的祖父标签，没有直接选中父标签权重为 0，蓝色样式选中了  <code>&lt;p&gt;</code>  标签的父标签  <code>&lt;div&gt;</code>  并有 1 个 id 选择器与 1 个类选择器，显然带有 id 选择器的蓝色样式权重最高，故字体为蓝色</p> <h3 id="样式表权重"><a href="#样式表权重" class="header-anchor">#</a> 样式表权重</h3> <p>CSS 样式有 3 中引入方式</p> <ol><li>行内样式：在标签中直接用  <code>style</code>  属性定义的样式</li> <li>内嵌样式表：在页面中用  <code>&lt;style&gt;&lt;/style&gt;</code>  定义的样式区块</li> <li>外部样式表：通过链接引入的外部样式文件</li></ol> <p>样式表的优先级为：行内样式 &gt; 内嵌样式表 &gt; 外部样式表</p> <h3 id="使用-important-提高权重"><a href="#使用-important-提高权重" class="header-anchor">#</a> 使用  <code>!important</code>  提高权重</h3> <p>我们可以在样式属性的后面添加  <code>!important</code>  来使其权重变为无穷大。</p> <div data-config="" data-type="vanilla" data-code="%3Chtml%3E%0A%0A%3Cstyle%3E%0A%20%20%20%20.test7%20.class1%20p%7B%0A%20%20%20%20%20%20%20%20color%3A%20green%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20.test7%20%23div1%20p%7B%0A%20%20%20%20%20%20%20%20color%3A%20red%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20.test7%20p%7B%0A%20%20%20%20%20%20%20%20color%3A%20blue%20!important%3B%0A%20%20%20%20%7D%0A%0A%3C%2Fstyle%3E%0A%0A%3Cdiv%20class%3D%22test7%22%3E%0A%20%20%20%20%3Cdiv%20class%3D%22class1%22%20id%3D%22div1%22%3E%0A%20%20%20%20%20%20%20%20%3Cp%3E%E6%88%91%E7%9A%84%E9%A2%9C%E8%89%B2%E6%98%AF%E4%BB%80%E4%B9%88%3C%2Fp%3E%0A%20%20%20%20%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%0A%3C%2Fhtml%3E%0A" class="vuepress-plugin-demo-block__wrapper" style="display:none;"><div class="vuepress-plugin-demo-block__display"><div class="vuepress-plugin-demo-block__app"></div></div> <div class="vuepress-plugin-demo-block__code"><div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
    <span class="token selector">.test7 .class1 p</span><span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> green<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token selector">.test7 #div1 p</span><span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    <span class="token selector">.test7 p</span><span class="token punctuation">{</span>
        <span class="token property">color</span><span class="token punctuation">:</span> blue <span class="token important">!important</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>test7<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>class1<span class="token punctuation">&quot;</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>div1<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>我的颜色是什么<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div></div> <div class="vuepress-plugin-demo-block__footer"></div></div> <p>上面的例子中 3 个选择器都直接选中了  <code>&lt;p&gt;</code>  标签，红色样式由于带有一个 id 选择器故其权重最大，但是由于蓝色样式添加了  <code>!important</code>  权重提升为无穷大，故最终为蓝色</p> <div class="custom-block warning"><p class="custom-block-title">注意</p> <p><code>!important</code>  书写格式要正确，与要提升权重的属性写在一起用空格隔开，分号写到最后</p> <ul><li><code>color: red !important;</code>  ✅</li> <li><code>color: red; !important;</code>  ❌ 没有写在一起，提前用分号隔开了</li> <li><code>color: red important;</code>  ❌ 丢失了感叹号</li></ul> <p><code>!important</code>  只会提升标记的属性，对其他属性不收影响</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">p</span> <span class="token punctuation">{</span>
    <span class="token comment">/* 只会提升颜色样式的权重，对于边框样式按照正常权重计算*/</span>
    <span class="token property">color</span><span class="token punctuation">:</span> red <span class="token important">!important</span><span class="token punctuation">;</span>
    <span class="token property">border</span><span class="token punctuation">:</span> 1px red solid<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><code>!important</code>  不影响通过继承获得的样式权重，如果某个样式的权重为 0，则添加  <code>!important</code>  后其权重依然为 0，最终权重按照前面 <a href="#%E6%9C%AA%E7%9B%B4%E6%8E%A5%E9%80%89%E4%B8%AD%E5%85%83%E7%B4%A0%E6%97%B6%E7%9A%84%E6%9D%83%E9%87%8D%E8%AE%A1%E7%AE%97">未直接选中元素时的权重计算</a> 小节中的方法计算</p></div> <h3 id="权重总结"><a href="#权重总结" class="header-anchor">#</a> 权重总结</h3> <h4 id="选择器权重-2"><a href="#选择器权重-2" class="header-anchor">#</a> 选择器权重</h4> <p>id 选择器 &gt; 类选择器 &gt; 标签选择器</p> <h4 id="样式表权重-2"><a href="#样式表权重-2" class="header-anchor">#</a> 样式表权重</h4> <p>行内样式 &gt; 内嵌样式表 &gt; 外部样式表</p> <p>行内样式的权重最大，无论内嵌样式表与外部样式表样式如何优先执行行内样式 (带有  <code>!important</code>  的除外)。</p> <h4 id="id-选择器权重最大"><a href="#id-选择器权重最大" class="header-anchor">#</a> id 选择器权重最大</h4> <p>外部样式表的 ID 选择器 &gt; 内嵌样式表的标签选择器</p> <h4 id="相同样式表权重计算"><a href="#相同样式表权重计算" class="header-anchor">#</a> 相同样式表权重计算</h4> <ul><li>查看目标标签是否直接选中，如果都没有选中按照继承的权重计算处理</li> <li>直接选中通过不同选择器的数量计算权重，权重相同谁写在最后听谁的</li> <li>直接选中的属性如果带有  <code>!important</code> ，则其权重提升</li></ul> <h4 id="引用多个样式表权重-就近原则"><a href="#引用多个样式表权重-就近原则" class="header-anchor">#</a> 引用多个样式表权重 (就近原则)</h4> <p>如果一个标签使用了多个相同的内嵌样式表，则定义的样式表中谁最近使用谁</p> <p>如果一个标签使用了多个相同的外部样式表，则 html 文件中引用的哪个外部样式表最近使用谁 (后加载的样式表会覆盖之前加载的样式表的相同属性)</p></div> <footer class="page-edit" style="display:none;"><!----> <!----></footer> <!----> <!----></main> <!----> <div class="comments-wrapper" data-v-0cb1c278><div class="valine-wrapper"><div id="valine"></div></div></div></div></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-a81d141e data-v-a81d141e><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-a81d141e><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-a81d141e></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-a81d141e></path></svg></div><canvas id="vuepress-canvas-ribbon"></canvas><div class="my-popup" style="display:none;" data-v-3414bdeb><div class="my-popup-container" data-v-3414bdeb><div class="my-popup-exit" data-v-3414bdeb></div> <img src="" alt data-v-3414bdeb></div></div><div data-v-2ebabc0c></div><div class="kanbanniang" data-v-3b0f9b07><div class="banniang-container" style="display:;" data-v-3b0f9b07><div class="messageBox" style="right:68px;bottom:230px;display:none;" data-v-3b0f9b07>
      欢迎来到 KnightSama‘s Blog
    </div> <div class="operation" style="right:90px;bottom:40px;display:;" data-v-3b0f9b07><i class="kbnfont kbn-ban-home ban-home" data-v-3b0f9b07></i> <i class="kbnfont kbn-ban-message message" data-v-3b0f9b07></i> <i class="kbnfont kbn-ban-close close" data-v-3b0f9b07></i> <a target="_blank" href="https://vuepress-theme-reco.recoluan.com/views/plugins/kanbanniang.html" data-v-3b0f9b07><i class="kbnfont kbn-ban-info info" data-v-3b0f9b07></i></a> <i class="kbnfont kbn-ban-theme skin" style="display:;" data-v-3b0f9b07></i></div> <canvas id="banniang" width="200" height="260" class="live2d" style="right:90px;bottom:-20px;opacity:0.9;" data-v-3b0f9b07></canvas></div> <div class="showBanNiang" style="display:none;" data-v-3b0f9b07>
    看板娘
  </div></div></div></div>
    <script src="/assets/js/app.a2483de7.js" defer></script><script src="/assets/js/4.0078dadf.js" defer></script><script src="/assets/js/1.c3e7d2b0.js" defer></script><script src="/assets/js/29.90552487.js" defer></script>
  </body>
</html>
